package com.zty.xiaomi.server.Config;

import com.alibaba.fastjson.JSONObject;
import com.zty.xiaomi.server.Entity.EmailMessage;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Losca
 * @date 2022/2/5 11:04
 */
@Component
@Aspect
public class UserAop {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @AfterReturning(value = "execution(* com.zty.xiaomi.server.Controller.LogRegController.Register(..))")
    public void sendMail(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        String username = (String) args[0];
        String email = (String) args[1];
        String password = (String) args[2];
        EmailMessage emailMessage = new EmailMessage(email
                ,"您已经成功注册,登陆名为:"+username+",密码为:"+password
        ,"系统消息");
        rabbitTemplate.convertAndSend("shop_email", JSONObject.toJSONString(emailMessage));


    }

}
